﻿using StrokeCenterSystem.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using StrokeCenterSystem.ThreeCenterManage;

namespace StrokeCenterSystem.Bll
{
    public class MedicalRecordsManager : BaseManager
    {
        public static ThreeCenterManageSoapClient service = new ThreeCenterManageSoapClient();

        /// <summary>
        /// 获取卒中病历
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public static OperateResult GetCaseHistory(string patientId)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfString result = service.GetCaseHistory(patientId);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }

        /// <summary>
        /// 获取当前急救人列表
        /// </summary>
        /// <returns></returns>
        public static OperateResult GetPathNameList()
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfString result = service.GetPathNameList();
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }

        /// <summary>
        /// 根据诊疗路径ID获取模板或内容
        /// </summary>
        /// <param name="pathId"></param>
        /// <returns></returns>
        public static OperateResult GetDiagnosticPathTemp(int pathId, string patientId)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfString result = service.GetDiagnosticPathTemp(pathId, patientId);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }


        /// <summary>
        /// 修改卒中病历
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public static OperateResult SetCaseHistory(string CaseJson)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfBoolean result = service.SetCaseHistory(CaseJson);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }

        #region 卒中四个病历存取


        /// <summary>
        /// CEA 、 CAS 病历获取
        /// </summary>
        /// <param name="Patient_ID"></param>
        /// <returns></returns>
        public static OperateResult Get_CEACAS(string Patient_ID)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfString result = service.Get_CEACAS(Patient_ID);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                    resultInfo.Result = 1;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }
        /// <summary>
        /// 静脉溶栓、血管内介入  病历获取
        /// </summary>
        /// <param name="Patient_ID"></param>
        /// <returns></returns>
        public static OperateResult Get_IntravenousThrombolysis(string Patient_ID)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfString result = service.Get_IntravenousThrombolysis(Patient_ID);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                    resultInfo.Result = 1;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }
        /// <summary>
        /// 脑出血  病历获取
        /// </summary>
        /// <param name="Patient_ID"></param>
        /// <returns></returns>
        public static OperateResult Get_Cerebralhemorrhage(string Patient_ID)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfString result = service.Get_Cerebralhemorrhage(Patient_ID);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                    resultInfo.Result = 1;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }
        /// <summary>
        /// 颅内动脉瘤   病历获取
        /// </summary>
        /// <param name="Patient_ID"></param>
        /// <returns></returns>
        public static OperateResult Get_IntracranialAneurysm(string Patient_ID)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfString result = service.Get_IntracranialAneurysm(Patient_ID);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                    resultInfo.Result = 1;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 新增或修改病人病历(CEA 、 CAS)
        /// </summary>
        /// <param name="patientViewModel"></param>
        /// <returns></returns>
        public static OperateResult Set_CEACAS(string patientViewModel)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfBoolean result = service.Set_CEACAS(patientViewModel);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.M;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }
        /// <summary>
        /// 新增或修改病人病历(静脉溶栓、血管内介入)
        /// </summary>
        /// <param name="patientViewModel"></param>
        /// <returns></returns>
        public static OperateResult Set_IntravenousThrombolysis(string patientViewModel)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfBoolean result = service.Set_IntravenousThrombolysis(patientViewModel);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.M;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }
        /// <summary>
        /// 新增或修改病人病历(脑出血)
        /// </summary>
        /// <param name="patientViewModel"></param>
        /// <returns></returns>
        public static OperateResult Set_Cerebralhemorrhage(string patientViewModel)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfBoolean result = service.Set_Cerebralhemorrhage(patientViewModel);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.M;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }
        /// <summary>
        /// 新增或修改病人病历(颅内动脉瘤)
        /// </summary>
        /// <param name="patientViewModel"></param>
        /// <returns></returns>
        public static OperateResult Set_IntracranialAneurysm(string patientViewModel)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfBoolean result = service.Set_IntracranialAneurysm(patientViewModel);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.M;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }
        #endregion

        /// <summary>
        /// 获取患者是否选择卒中诊断
        /// </summary>
        /// <param name="CaseJson"></param>
        /// <returns></returns>
        public static OperateResult Get_StrokeDiagnosis(string Patient_ID)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfNullableOfInt32 result = service.Get_StrokeDiagnosis(Patient_ID);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }
        /// <summary>
        /// 修改时间点数据
        /// </summary>
        /// <param name="Patient_ID"></param>
        /// <returns></returns>
        public static OperateResult Set_ExecutionDate(string patientViewModel)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfBoolean result = service.Set_ExecutionDate(patientViewModel);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.M;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }
        /// <summary>
        /// 获取时间点数据
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public static OperateResult Get_PatientTimePath(string Patient_ID)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfString result = service.Get_PatientTimePath(Patient_ID);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                    resultInfo.Result = 1;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 获取患者未选择卒中类型时候选填的基础信息
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public static OperateResult GetPatinet_BaseInfor(string patientId)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfString result = service.GetPatinet_BaseInfor(patientId);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                    resultInfo.Result = 1;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 更新患者未选择卒中类型时候选填的基础信息"
        /// </summary>
        /// <param name="datajson"></param>
        /// <returns></returns>
        public static OperateResult SetPatinet_BaseInfor(string datajson)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfBoolean result = service.SetPatinet_BaseInfor(datajson);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.M;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }

        /// <summary>
        /// 保存审核信息
        /// </summary>
        /// <param name="datajson"></param>
        /// <returns></returns>
        public static OperateResult ReviewSave(string pid, int state, string message,string reviewName)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ResultHelperOfBoolean result = service.SetPatientApprovalStatus(pid, message, state, reviewName);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.M;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }
    }
}